#include "common.h"


typedef struct 
{
	char name[MAX_LEN];
	int usedcount;
	int year;
	char genre[MAX_LEN];
} movie_t;

typedef struct
{
	char name[MAX_LEN];
	int score;
} player_t;

typedef struct 
{
	char name[MAX_LEN];
	int usedcount;
	int from_year;
	int to_year;
	int num_of_players;
	player_t * players;
} game_t;

typedef struct
{
	char name[MAX_LEN];
	int usedcount;
	int num_of_songs;
	char genre[MAX_LEN];
} playlist_t;

int movies_count = 0;
movie_t * movies_arr = NULL;
int games_count = 0;
game_t * games_arr = NULL;
int playlists_count = 0;
playlist_t * playlists_arr = NULL;



success_t cmd_add_movie(FILE * outstream, char ** args)
{
	int i;
	char * name = args[0];
	
	for (i = 0; i < movies_count; i++)
	{
		if (strcmp(movies_arr[i].name, name) == 0)
		{
			/* ERROR: movie already exists */
			return FALSE;
		}
	}
	
	i = movies_count;
	movies_count++;
	movies_arr = realloc(movies_arr, sizeof(movie_t) * movies_count);
	strcpy(movies_arr[i].name, name);
	movies_arr[i].usedcount = 0;
	movies_arr[i].year = 0;
	strcpy(movies_arr[i].genre, "General");
	
	return TRUE;
}

success_t cmd_remove_movie(FILE * outstream, char ** args)
{
	int i;
	char * name = args[0];
	
	for (i = 0; i < movies_count; i++)
	{
		if (strcmp(movies_arr[i].name, name) == 0)
		{
			memcpy(&movies_arr[i], &movies_arr[i+1], 
				sizeof(movie_t) * (movies_count - i - 1));
			movies_count--;
			movies_arr = realloc(movies_arr, sizeof(movie_t) * movies_count);
			return TRUE;
		}
	}
	
	/* ERROR: movie already exists */
	return FALSE;
}

















